<?php
function daemon()
{
    $pid = pcntl_fork();
    if ($pid < 0) die("fork err");
    if ($pid == 0) {
        if (posix_setsid() <= 0) {
            die("setsid err!");
        }
        if (chdir('/') === false) {
            die("change dir err");
        }
        umask(0);
        fclose(STDIN);
        fclose(STDOUT);
        fclose(STDERR);

    } else {
        echo posix_getpid()." exit ".PHP_EOL;
        exit();
    }
}